package com.bsc.minacommand.model;

import org.apache.commons.lang.StringUtils;

public final class BscCommandFactory {

    private BscCommandFactory() {
    }

    public static AbstractBscCommand newCommand(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        if (StringUtils.isNotEmpty(name)) {
            Class clazz = Class.forName("com.bsc.minacommands.concrete." + name);
            if (clazz != null) {
                if (AbstractBscCommand.class.isAssignableFrom(clazz)) {
                    return (AbstractBscCommand) clazz.newInstance();
                }
            }
        }
        return null;
    }
}
